package com.myccb.app;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Base64;

import com.myccb.app.view.activity.LoginActivity;

/**
 * Created by hyt on 2017/12/8.
 */

public class AppStatus {

    private Context context;

    public static boolean isLogin=false;

    public static String lastLoginTime="";

    private static AppStatus instance;

    private AppStatus(Context context){
        this.context=context;
    }

    public static void createInstance(Context context){

        if (instance==null)
            instance=new AppStatus(context);
    }

    public static AppStatus getInstance(){
        return instance;
    }

    public boolean isSaveUserInfo(){
        SharedPreferences sp=context.getSharedPreferences("login_status", Context.MODE_PRIVATE);
        return sp.getBoolean("one_user_login_success",false);
    }

    public String getSavedUserName(){
        SharedPreferences sp=context.getSharedPreferences("login_status", Context.MODE_PRIVATE);
        String info = sp.getString("user_info","none");
        if (!info.equals("none")){
            info= new String(Base64.decode(info,Base64.DEFAULT));
            return info.split(",")[0];
        }
        return null;
    }

    public String getSavedIDNum(){

        SharedPreferences sp=context.getSharedPreferences("login_status", Context.MODE_PRIVATE);

        String info = sp.getString("user_info","none");
        if (!info.equals("none")){
            info= new String(Base64.decode(info,Base64.DEFAULT));
            return info.split(",")[2];
        }

        return null;
    }

    public static void startLoginActivity(Activity activity){
        Intent intent=new Intent(activity,LoginActivity.class);
        activity.startActivityForResult(intent,1);
        activity.overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
    }
}
